<html layout:decorate="~{project/indexManage/target_list}" xmlns:layout="http://www.w3.org/1999/xhtml">
<div layout:fragment="content_list">

    <style>
        .search-data{
            width: 150px;
        }
    </style>
    <div class="main-body">
            <div class="search_condition">
                <form id="search-form">
                    <input class="search-data" name="Q_LIKE_name" type="text" placeholder="名称">
                    <!--th:value="${Q_LIKE_name}"-->
                    <select class="search-data" name="Q_EQ_objName">
                        <option value="">适用对象</option>
                        <option th:each="parameter:${objNames}" th:value="${parameter.remark}"
                                th:text="${parameter.name}"></option>
                        <!--th:selected="${parameter.remark eq Q_EQ_objName}"-->
                    </select>
                    <select class="search-data" name="Q_EQ_source">
                        <option value="">来源</option>
                        <option th:each="parameter:${sources}" th:value="${parameter.remark}"
                                th:text="${parameter.name}"></option>
                        <!--th:selected="${parameter.remark eq Q_EQ_source}"-->
                    </select>
                    <select class="search-data" name="Q_EQ_isShow">
                        <option value="">是否展示</option>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                    <!--<input type="checkbox" name="isShow" value="0" onclick="this.value=(this.value==0)?1:0">-->
                    <button type="button" id="search-btn" class="btn btn-primary btn-search"
                            onclick="search('dataTable')">搜索
                    </button>
                </form>
            </div>
        <!-----------------------------------------按钮组------------------------------------------------------------->
        <div id="toolbar" class="btn-group btn-group-sm">

            <a type="button" class="btn btn-primary" data-toggle="modal"
               href="/project/indexManage/warn_add" data-target="#modal">新增</a>

            <a type="button" id="btn" class="btn btn-danger">删除</a>
            <a type="button" onclick="editData('/project/indexManage/warn_edit','id')"
               class="btn btn-info">编辑</a>
            <a type="button" href="/project/indexManage/warn_importData" class="btn btn-success"
               data-toggle="modal"
               data-target="#modal">导入数据</a>
            <a type="button" href="/project/indexManage/warn_exportData" class="btn btn-success">导出数据</a>
        </div>


        <table id="dataTable" data-url="/project/indexManage/warn_data" data-page-list=[] data-striped="true"
               data-pagination="true" data-page-size="15" data-cache="false" data-toolbar-align="right">
        </table>
        <script>
            //过程报警
            var dataFormat_warn = [{
                checkbox: true
            }, {
                field: 'id',
                title: 'id',
                visible: false
            }, {
                field: 'code',
                title: '编号'
            }, {
                field: 'name',
                title: '名称'
            }, {
                field: 'objName',
                title: '适用对象',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return '项目';
                    }
                    if (value == 2) {
                        return '电池包';
                    }
                    if (value == 3) {
                        return '电池模组';
                    }
                    if (value == 4) {
                        return '变流器';
                    }
                    if (value == 5) {
                        return '电池单体';
                    }

                }
            },
                {
                    field: 'objType',
                    title: '所属类别',
                    formatter: function (value, row, index) {

                        if (value == 1) {
                            return '电池故障';
                        }
                        if (value == 2) {
                            return '变流电故障';
                        }

                    }
                }, {
                    field: 'source',
                    title: '来源',
                    formatter: function (value, row, index) {
                        if (value == 1) {
                            return '计算';
                        }
                        if (value == 2) {
                            return '诊断';
                        }
                        if (value == 3) {
                            return '通信';
                        }
                    }
                }, {
                    field: 'alarmLev',
                    title: '默认报警等级',
                    formatter: function (value, row, index) {
                        if (value == 1) {
                            return "一级"
                        }
                        if (value == 2) {
                            return "二级"
                        }
                        if (value == 3) {
                            return "三级"
                        }
                        if (value == 4) {
                            return "四级"
                        }
                        if (value == 5) {
                            return "无"
                        }
                    }
                }, {
                    field: 'manageWay',
                    title: '建议处理方式',
                    formatter: function (value, row, index) {
                        if (value == 1) {
                            return "建立现场处理"
                        }
                        if (value == 2) {
                            return "建议通知工程师"
                        }
                        if (value == 3) {
                            return "建议关闭系统"
                        }
                        if (value == 4) {
                            return "建议跟踪观察"
                        }
                    }
                }, {
                    field: 'isRecordSoe',
                    title: '是否需要事故记录SOE',
                    formatter: function (value, row, index) {
                        if (value == 0) {
                            return '<input type = "checkbox">'
                        }
                        if (value == 1) {
                            return '<input type="checkbox" checked>';
                        }
                    }
                }, {
                    field: 'soeDuration',
                    title: 'SOE前后时长(秒/s)'
                },
                {
                    field: 'isShow',
                    title: '是否展示',
                    formatter: function (value, row, index) {

                        if (value == 1) {
                            return '<input type="checkbox" checked>';
                        }
                        if (value == 0) {
                            return '<input type = "checkbox" >';
                        }
                    }
                },
                {
                    field: 'parameterCode',
                    title: '关联测点'
                }
                , {
                    field: 'operator',
                    title: '运算符'
                }
                , {
                    field: 'thresholdCode',
                    title: '关联阈值'
                }];

            window.onload = function () {
                getTable("search-data",dataFormat_warn, "dataTable");
            };
            /**********************************************删除二次确认*********************************************/
            $(function () {
                $("#btn").click(function (id) {
                    var idResult = "dataTable";
                    var table = $("#" + idResult).bootstrapTable('getSelections');
                    if (table.length == 0) {
                        alert("请选择至少选择一条数据删除");
                        return false;
                    }
                    var bfm = confirm("请确认是否删除?")
                    if (bfm) {
                        delDatas('/project/indexManage/warn_del');
                    }
                });
            });
            /**************************条件搜索**********************/
            function getTable(searchClass, dataFormat, id) {
                $("#" + id).bootstrapTable({
                    method: "get",
                    sidePagination: "server",
                    dataType: "json",
                    queryParams: function queryParams(params) {   //设置查询参数
                        var param = {
                            pageNum: params.offset / params.limit
                        };
                        $("." + searchClass).each(function () {
                            var key = $(this).attr("name");
                            var val = $(this).val();
                            console.log(key+"===="+val);
                            param[key] = val;
                        });
                        //  console.log(param);
                        return param;
                    },
                    columns: dataFormat
                });
            }
            function search(id) {
                $("#" + id).bootstrapTable("selectPage", 1);
            }

        </script>
    </div>
</div>
</html>